package com.wanhai.itm.services;

import com.wanhai.itm.entity.User;
import java.io.StringReader;
import org.zkoss.json.JSONObject;
import org.zkoss.json.JSONValue;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WebApps;

/**
 *
 * @author Richard Shih
 */
public class UserInfoServiceImpl extends UserInfoService {
    
    @Override
    public User findUser(String userid) {
        //fetch all user's information here
        
        String loginUsers = WebApps.getCurrent().getConfiguration().getPreference("login-users", null);
        JSONObject users = (JSONObject) JSONValue.parse(loginUsers);
        if (users != null && users.containsKey(userid)) {
            JSONObject userObj = (JSONObject) users.get(userid);
            User user = new User(null);
            user.setUserName(String.valueOf(userObj.get("name")));
            user.setUserCode(userid);
            user.setSectionCode(String.valueOf(userObj.get("section_code")));
            return user;
        }
        return null;
        
    }
    
    @Override
    public User updateUser(User user) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
